using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_ShopIndexArticle : Admin, IRequiresSessionState
{
	protected HyperLink AddNew;
	protected DropDownList QuickSearch;
	protected CheckBoxList CheckBoxList1;
	protected GridView GridView1;
	protected Label pagePanel;
	protected Button DeleteBtn;
	protected Button Button1;
	protected Button Button2;
	protected Button Button3;
	protected Button Button4;
	protected Button Button5;
	protected Button Button6;
	protected string pagelinkhead = "";
	protected string whereStr = "";
	protected bool ebquest = true;
	protected int ModuleID = 0;
	private int pageIndx;
	private Shop_Module _module = null;
	private Shop_Article _article = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected Shop_Module module
	{
		get
		{
			Shop_Module module;
			if (this._module == null)
			{
				this._module = new Shop_Module(this.conn);
				module = this._module;
			}
			else
			{
				module = this._module;
			}
			return module;
		}
	}
	protected Shop_Article m_article
	{
		get
		{
			Shop_Article article;
			if (this._article == null)
			{
				this._article = new Shop_Article(this.conn);
				article = this._article;
			}
			else
			{
				article = this._article;
			}
			return article;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.admin.CheckAdminPower(10))
		{
			base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Article");
			base.WriteRightErrMsg();
		}
		this.ModuleID = Fetch.GetID("ModuleID");
		this.pageIndx = Fetch.GetID("Page");
		if (this.pageIndx == 0)
		{
			this.pageIndx = 1;
		}
		if (!base.IsPostBack)
		{
			if (this.ModuleID > 0)
			{
				this.AddNew.NavigateUrl = "Admin_ShopIndexArticleAdd.aspx?ModuleID=" + this.ModuleID;
			}
			this.BindQuickSearch();
			this.BandPages();
		}
	}
	protected void BindQuickSearch()
	{
		DataTable allModule = this.module.GetAllModule();
		this.QuickSearch.DataSource = allModule;
		this.QuickSearch.DataTextField = "Title";
		this.QuickSearch.DataValueField = "id";
		this.QuickSearch.DataBind();
		if (this.ModuleID > 0)
		{
			try
			{
				this.QuickSearch.SelectedValue = this.ModuleID.ToString();
			}
			catch
			{
			}
		}
	}
	protected void BandPages()
	{
		this.GetQuestString();
		int pagesize = 15;
		if (this.GridView1.PageSize != 0)
		{
			pagesize = int.Parse(this.GridView1.PageSize.ToString());
		}
		this.GridView1.DataSource = this.m_article.GetAllArticle(this.pageIndx, this.whereStr, pagesize);
		this.GridView1.DataBind();
		this.pagePanel.Text = this.m_article.ShowPagePanel(this.pagelinkhead);
	}
	protected void GetQuestString()
	{
		string text = Fetch.Get("QuickSearch");
		if (text != "" && text != "0" && this.ebquest)
		{
			this.QuickSearch.SelectedValue = text;
		}
		else
		{
			text = this.QuickSearch.SelectedValue.ToString();
		}
		if (text != string.Empty && text != "0")
		{
			if (Convert.ToInt32(text) > 0)
			{
				object obj = this.whereStr;
				this.whereStr = string.Concat(new object[]
				{
					obj,
					"and ChannelID=",
					Convert.ToInt32(text),
					" "
				});
				this.AddNew.NavigateUrl = "Admin_ShopIndexArticleAdd.aspx?ModuleID=" + Convert.ToInt32(this.QuickSearch.SelectedValue);
			}
			else
			{
				string text2 = text;
				if (text2 != null)
				{
					if (!(text2 == "-1"))
					{
						if (!(text2 == "-2"))
						{
							if (text2 == "-3")
							{
								this.whereStr += "and [HLShop_IndexArticle].[Status]=1 ";
							}
						}
						else
						{
							this.whereStr += "and [HLShop_IndexArticle].[Status]=-1 ";
						}
					}
					else
					{
						this.whereStr += "and [HLShop_IndexArticle].[Status]=0 ";
					}
				}
				this.AddNew.NavigateUrl = "Admin_ShopIndexArticleAdd.aspx";
			}
			this.pagelinkhead = this.pagelinkhead + "&QuickSearch=" + text;
		}
		string text3 = Fetch.Get("Att");
		if (text3 != string.Empty && this.ebquest)
		{
			for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
			{
				if (text3.Contains(this.CheckBoxList1.Items[i].Value))
				{
					this.CheckBoxList1.Items[i].Selected = true;
				}
			}
			this.pagelinkhead = this.pagelinkhead + "&Att=" + base.Server.UrlEncode(text3);
		}
		else
		{
			string text4 = "";
			for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
			{
				if (this.CheckBoxList1.Items[i].Selected)
				{
					text4 = text4 + "," + this.CheckBoxList1.Items[i].Value;
				}
				if (text4 != "")
				{
					text4 = "," + text4;
					text4 = text4.Replace(",,", "");
				}
			}
			if (text4 != "")
			{
				text3 = text4;
				this.pagelinkhead = this.pagelinkhead + "&Att=" + base.Server.UrlEncode(text4);
			}
		}
		if (text3 != string.Empty)
		{
			if (text3.Contains("ontop"))
			{
				this.whereStr += "and [HLShop_IndexArticle].[OnTop]=1 ";
			}
			if (text3.Contains("iselite"))
			{
				this.whereStr += "and [HLShop_IndexArticle].[Elite]=1 ";
			}
			if (text3.Contains("ishots"))
			{
				this.whereStr += "and [HLShop_IndexArticle].[Hits]>=50 ";
			}
		}
		SiteConfigBll siteConfigBll = new SiteConfigBll();
		if (siteConfigBll.GetSiteString("SiteConfigInfo/CityArea") != "0" && !base.admin.CheckSuperAdmin())
		{
			this.whereStr = this.whereStr + "and Editor = '" + base.admin.AdminName + "'";
		}
		if (this.whereStr != "")
		{
			this.whereStr = "and" + this.whereStr;
			this.whereStr = this.whereStr.Replace("andand", "Where");
		}
	}
	protected void QuickSearch_SelectedIndexChanged(object sender, EventArgs e)
	{
		if (Convert.ToInt32(this.QuickSearch.SelectedValue) > 0)
		{
			this.AddNew.NavigateUrl = "Admin_ShopIndexArticleAdd.aspx?ModuleID=" + Convert.ToInt32(this.QuickSearch.SelectedValue);
		}
		else
		{
			this.AddNew.NavigateUrl = "Admin_ShopIndexArticleAdd.aspx";
		}
		this.ebquest = false;
		this.pageIndx = 1;
		this.BandPages();
	}
	protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.ebquest = false;
		this.pageIndx = 1;
		this.BandPages();
	}
	protected void ArticleButtonOnCommon(object sender, CommandEventArgs e)
	{
		if (e.CommandName != null)
		{
			bool flag = false;
			string text = e.CommandName.ToString();
			switch (text)
			{
			case "delete":
				if (base.admin.CheckAdminPower(10))
				{
					flag = true;
				}
				break;
			case "ontop":
				if (base.admin.CheckAdminPower(10))
				{
					flag = true;
				}
				break;
			case "cancleontop":
				if (base.admin.CheckAdminPower(10))
				{
					flag = true;
				}
				break;
			case "iselite":
				if (base.admin.CheckAdminPower(10))
				{
					flag = true;
				}
				break;
			case "cancleelite":
				if (base.admin.CheckAdminPower(10))
				{
					flag = true;
				}
				break;
			case "pass":
				if (base.admin.CheckAdminPower(10))
				{
					flag = true;
				}
				break;
			case "nopass":
				if (base.admin.CheckAdminPower(10))
				{
					flag = true;
				}
				break;
			}
			if (!flag)
			{
				base.WriteRightErrMsg();
			}
			string text2 = base.Request["chk_select"];
			if (text2 != "" && text2 != null)
			{
				this.m_article.EditArticle(e.CommandName.ToString(), text2);
			}
			this.ebquest = false;
			this.BandPages();
		}
	}
	protected void GridView1_DataBound(object sender, EventArgs e)
	{
		string str = "";
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			if (gridViewRow.RowType == DataControlRowType.DataRow)
			{
				LinkButton linkButton = (LinkButton)gridViewRow.FindControl("LinkButton");
				if (!base.admin.CheckAdminPower(29))
				{
					if (linkButton != null)
					{
						linkButton.Enabled = false;
					}
				}
				gridViewRow.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
				gridViewRow.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
				Literal literal = (Literal)gridViewRow.FindControl("ArticleType");
				HiddenField hiddenField = (HiddenField)gridViewRow.FindControl("PicUrl");
				string str2 = "<a href=\"#\" onmouseover='showPreview(event);' onmouseout='hidePreview(event);'><img src=\"Images/media.png\" large_src=\"" + hiddenField.Value + "\" border=0/></a>";
				string text = literal.Text;
				if (text != null)
				{
					if (!(text == "IMG"))
					{
						if (!(text == "Text"))
						{
							if (text == "IMGText")
							{
								literal.Text = "图文" + str2;
							}
						}
						else
						{
							literal.Text = "文字";
						}
					}
					else
					{
						literal.Text = "图片" + str2;
					}
				}
				Literal literal2 = (Literal)gridViewRow.FindControl("ChectType");
				Literal literal3 = (Literal)gridViewRow.FindControl("LinkType");
				HyperLink hyperLink = (HyperLink)gridViewRow.FindControl("Detail");
				if (literal3.Text == "本文章链接")
				{
					hyperLink.NavigateUrl = str + "Shop/Article/Index.aspx?aid=" + gridViewRow.Cells[1].Text;
				}
				text = literal2.Text;
				if (text == null)
				{
					goto IL_272;
				}
				if (!(text == "0"))
				{
					if (!(text == "1"))
					{
						if (!(text == "-1"))
						{
							goto IL_272;
						}
						literal2.Text = Language.GetAdminMsg("Article/Status/Status3");
					}
					else
					{
						literal2.Text = Language.GetAdminMsg("Article/Status/Status2");
					}
				}
				else
				{
					literal2.Text = Language.GetAdminMsg("Article/Status/Status1");
				}
				continue;
				IL_272:
				literal2.Text = "未知";
			}
		}
	}
}
